package com.nh.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;


/**
 * @Author: LaoCao
 * @Date: 2023/3/16 9:40
 * @Version: 1.0
 **/
@Configuration
public class ExecutorConfig {
    int corePoolSize = 40;
    int maximumPoolSize = 40;
    long keepAliveTime  = 10;
    TimeUnit unit = TimeUnit.MICROSECONDS;
    BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(5000);
    ThreadFactory threadFactory =  Executors.defaultThreadFactory();
    RejectedExecutionHandler handler = new ThreadPoolExecutor.AbortPolicy();

    @Bean
    public AbstractExecutorService threadPoolExecutor(){
        return new ThreadPoolExecutor(
                corePoolSize,
                maximumPoolSize,
                keepAliveTime,
                unit,
                workQueue,
                threadFactory,
                handler
        );
    }


}
